package com.yu1996.Recursive;


/**
 * @Description: 递归算法的测试类
 * @author: xing
 * @Date: ` 14:29
 */
public class RecursiveDemo {

    public static void main(String[] args) {
        //测试递归输出
//        SystemOut(4);
        //测试递归实现数的阶乘
        int factorial = Factorial(5);
        System.out.println(factorial);
    }


    /**
     * @Description 递归实现输出
     * @Author xing
     * @Date 2019/8/12 14:22
     * @Param
     * @Return
     * @Exception
     */
    public static void SystemOut(int i) {
        if (i > 2) {
            SystemOut(i - 1);
        }
        System.out.println("n = " + i);
    }


    /**
     * @Description 递归实现数阶乘的方法
     * @Author xing
     * @Date 2019/8/12 14:30
     * @Param
     * @Return
     * @Exception
     */
    public static int Factorial(int i) {
        int res = 1;
        if (i == 1) {
            res = res * i;
        } else {
            res = i * Factorial(i - 1);
        }
        return res;
    }
}
